package assignmentstrategy

import (
	"codejy/analysis/codeanalysis"
	"codejy/store"
	"codejy/structdef"
	"strings"
)

// 通过global.xxx获取全局变量的值
type GlobalPropStrategy struct {
}

func init() {
	RegisterStrategy(&GlobalPropStrategy{})
}
func (n GlobalPropStrategy) getId() int {
	return codeanalysis.GlobalProp
}

func (n GlobalPropStrategy) Execute(threadStore *structdef.ThreadStore, code string) string {
	index := strings.Index(code, ".")
	getVariable, b := store.GetGlobalVariable(threadStore, code[index+1:])
	if b {
		return getVariable.Value
	} else {
		panic("错误::::::全局变量中没有" + code + "的定义")
	}
}
